﻿using Furion;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Htx.Fur.Core.ContextLocators;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Htx.Fur.EntityFramework.Core
{
    public class Startup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDatabaseAccessor(options =>
            {
                options.AddDbPool<DefaultDbContext>();

                options.AddDbPool<SqliteDbContext, SqliteDbContextLocator>();

            }, "Htx.Fur.Database.Migrations");
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // 判断开发环境！！！必须！！！！
            //if (env.IsDevelopment())
            //{
            //    Scoped.Create((_, scope) =>
            //    {
            //        // 数据库自动迁移
            //        var context = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
            //        context.Database.Migrate();
            //        //context.Database.EnsureCreated();   // 如果没有生成过 Migrations 文件情况
            //        //context.Database.EnsureDeleted();   // 删除之前的数据库
            //    });
            //}

        }

    }
}